import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {InputItem, Button,Flex, List} from 'antd-mobile';
import './SendText.css';

class SendText extends Component {
    
    static propTypes = {
        sendMessage:PropTypes.func.isRequired,
        chatState:PropTypes.object.isRequired,
        sendChatMessage:PropTypes.object.isRequired
    }
        
    /*componentDidMount()
  {
    const {fetchFriendMessage,login,friendState} = this.props
    let userId = login.myAccount.uid
    let uid = friendState.currChatFriendId
    let url = "http://192.168.43.187:8080/lwj/basic/getMSG?uid1="+userId+"&uid2="+uid
    this.testState.timer = setInterval(()=>fetchFriendMessage(url),2000)
  }

  componentWillMount(){
      clearInterval(this.testState.timer)
  }
*/
    onSendClick(){
        const {sendMessage} = this.props;
        sendMessage(this.inputRef.state.value);

        const {sendChatMessage,login,friendState} = this.props
        //let uid = login.myAccount.uid
        //let uuid = friendState.currChatFriendId
        //let text = this.inputRef.state.value
        //let url ="http://192.168.43.187:8080/lwj/basic/message?uid="+uid+"&uuid="+uuid+"&content="+text
        //sendChatMessage(url)

        this.inputRef.state.value = "";
        console.log(document.getElementById("msg_end"));
        setTimeout(()=> document.getElementById("msg_end").scrollIntoView(),500);
    }

    render(){
        return(
            <List className = "my-footer">
                <InputItem  extra={<Button type="primary" size="small" inline className = "send-button" onClick = {()=>this.onSendClick()}  >发送</Button>} className = "my-input" name = 'message' ref = {input => this.inputRef = input} placeholder="输入聊天内容"/>
            </List>
        )
    }
}

export default SendText